home *** CD-ROM | disk | FTP | other *** search
/ ...taking it to the Macs! / ...taking it to the Macs!.iso / Extras / ActiveX Mac SDK / ActiveX SDK / Sample Controls / TextEdit / CTextEditBSC.cpp next >
Encoding:
Text File  |  1996-12-14  |  2.9 KB  |  127 lines  |  [TEXT/CWIE]

  1. // =================================================================================
  2. //
  3. //    CTextEditBSC.cpp                ©1996 Microsoft Corporation All rights reserved.
  4. //
  5. // =================================================================================
  6.  
  7. #include "ocheaders.h"
  8. #include "CTextEditBSC.h"
  9. #include "CTextEditControl.h"
  10. #include "urlmonsupport.h"
  11.  
  12. #pragma mark === CTextEditBSC::Construction & Destruction ===
  13.  
  14. //
  15. //    CTextEditBSC::CTextEditBSC
  16. //
  17. //    initialize our members
  18. //
  19.  
  20. CTextEditBSC::CTextEditBSC(void)
  21.     : CBaseBindStatusCallback()
  22. {
  23.     mData = NULL;
  24.     mBusy = false;
  25. }
  26.  
  27.  
  28. #pragma mark === CTextEditBSC::IBindStatusCallback ===
  29.  
  30. //
  31. //    CTextEditBSC::IBindStatusCallback::OnStopBinding
  32. //
  33. //    wrap up the stream
  34. //
  35.  
  36. STDMETHODIMP
  37. CTextEditBSC::OnStopBinding(ErrorCode Result, const Char8* Error)
  38. {
  39.     CBaseBindStatusCallback::OnStopBinding(Result, Error);
  40.     mBusy = false;
  41.     
  42.     return S_OK;
  43. }
  44.  
  45.  
  46. //
  47. //    CTextEditBSC::IBindStatusCallback::OnDataAvailable
  48. //
  49. //    data has become available - put it into our buffer
  50. //
  51.  
  52. STDMETHODIMP
  53. CTextEditBSC::OnDataAvailable(Uint32 BSCF, Uint32 Size, FORMATETC* FormatEtc, STGMEDIUM* StgMedium)
  54. {
  55.     OSErr Err = noErr;
  56.     
  57.     CBaseBindStatusCallback::OnDataAvailable(BSCF, Size, FormatEtc, StgMedium);
  58.     
  59.     if (StgMedium->pUnkForRelease != NULL)
  60.         StgMedium->pUnkForRelease->Release();
  61.  
  62.     return S_OK;
  63. }
  64.  
  65.  
  66. #pragma mark === CTextEditBSC::Public methods ===
  67.  
  68.  
  69. //=--------------------------------------------------------------------------=
  70. //  CBaseBindStatusCallback::OpenStream
  71. //=--------------------------------------------------------------------------=
  72. //
  73. ErrorCode
  74. CTextEditBSC::OpenPostStream(IContainerSite* inContainerSiteP, LPOLESTR URLString,
  75.         Handle PostData)
  76. {
  77.     ErrorCode            Result = E_FAIL;
  78.     LPBINDHOST            BindSiteP;
  79.     LPMONIKER            URLMoniker = NULL;
  80.     LPBINDCTX            BindContext = NULL;
  81.  
  82.     if(!mBusy)
  83.     {
  84.         inContainerSiteP->QueryInterface(IID_IBindHost, (LPVOID *) &BindSiteP);
  85.  
  86.         if (BindSiteP)
  87.         {
  88.             Result = BindSiteP->CreateMoniker((LPOLESTR)URLString, NULL, &URLMoniker, 0);
  89.             if(SUCCEEDED(Result) && URLMoniker)
  90.             {
  91.                 void*        Dummy;
  92.  
  93.                 mData = PostData;
  94.                 mBusy = true;
  95.                 Result = BindSiteP->MonikerBindToStorage(URLMoniker, NULL, 
  96.                         (IBindStatusCallback*)this, IID_IStream, &Dummy);
  97.                 if(Result == E_PENDING)
  98.                     Result = S_OK;
  99.                 URLMoniker->Release();
  100.             }
  101.         }
  102.     }
  103.     if(Result != S_OK)
  104.         DisposeHandle(PostData);
  105.  
  106.     return Result;
  107. }
  108.  
  109. //=--------------------------------------------------------------------------=
  110. //  CBaseBindStatusCallback::IBindStatusCallback::GetBindInfo
  111. //=--------------------------------------------------------------------------=
  112. //
  113. STDMETHODIMP
  114. CTextEditBSC::GetBindInfo(Uint32* BINDF, BINDINFO *BindInfo)
  115. {
  116.     *BINDF = BINDF_ASYNCHRONOUS | BINDF_ASYNCSTORAGE;
  117.     BindInfo->dwBindVerb = BINDVERB_POST;
  118.     BindInfo->cbstgmedData = GetHandleSize(mData);
  119.     BindInfo->stgmedData.tymed = TYMED_HGLOBAL;
  120.     BindInfo->stgmedData.hGlobal = mData;
  121.     AddRef();
  122.     BindInfo->stgmedData.pUnkForRelease = NULL;
  123.  
  124.     return S_OK;
  125. }
  126.  
  127.